package com.example.fbzdemooracke.config;

import com.example.fbzdemooracke.annotiation.TestAnnotiation;
import com.example.fbzdemooracke.interceptor.TestInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebConfigurer implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(testInterceptor()).addPathPatterns("/user/**");
        //除了Controller要有一个@TestAnnotiation之外 这里的addPathPatterns也必须有相应的前缀
    }

    @Bean
    public TestInterceptor testInterceptor(){
        return new TestInterceptor();
    }
}
